package git.soulbgm.mapreduce.combineTextInputForamt;

import git.soulbgm.mapreduce.utils.DriverUtil;
import git.soulbgm.mapreduce.wordcount.WordCountMapper;
import git.soulbgm.mapreduce.wordcount.WordCountReducer;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.CombineTextInputFormat;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

/**
 * @author SoulBGM
 * @date 2021/11/18 0:07
 */
public class WordCountDriver {

    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        Job job = DriverUtil.createJob(git.soulbgm.mapreduce.wordcount.WordCountDriver.class, WordCountMapper.class, WordCountReducer.class,
                Text.class, IntWritable.class, Text.class, IntWritable.class,
                new Path(args[0]), new Path(args[1]));

        // 设置输入格式 CombineTextInputFormat 组合文本输入格式
        job.setInputFormatClass(CombineTextInputFormat.class);
        // 设置最大输入分割大小 20M
        CombineTextInputFormat.setMaxInputSplitSize(job, 20971520);

        // 7 提交job
        boolean result = job.waitForCompletion(true);
        System.exit(result ? 0 : 1);

    }

}
